import { App, DefineComponent } from 'vue'

interface FileType {
  [key: string]: DefineComponent
}

const files: Record<string, FileType> = import.meta.globEager('./*/*.vue')

const install = function install(app: App) {
  Object.keys(files).forEach((c: string) => {
    const fileName = c.match(/[^/]([a-z]+)[^/]/gi)

    const component = files[c]?.default
    // 挂载全局控件
    // app.component(component.name as string, component)
    fileName?.length && app.component(fileName[0] as string, component)
  })
}

export default { install }
